package com.misic.wed;

import com.alibaba.fastjson.JSONObject;
import com.misic.pojo.Admin;
import com.misic.service.AdminService;
import com.misic.utils.Consts;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;

@RestController
public class AdminController {
    @Autowired
    //
    private AdminService adminService;
    /**
     * 判断是否登录成功
     */
    @PostMapping(value = "/admin/login")
    public  JSONObject loginStatus(Admin admin, HttpSession session){
        JSONObject jsonObject = new JSONObject();
        boolean flag = adminService.verifyPassword(admin.getName(),admin.getPassword());
        if(flag){
            jsonObject.put(Consts.CODE,1);
            jsonObject.put(Consts.MSG,"登录成功");
            session.setAttribute(Consts.NAME,admin.getName());
            return jsonObject;
        }
        jsonObject.put(Consts.CODE,0);
        jsonObject.put(Consts.MSG,"用户名或密码错误");
        return jsonObject;
    }
}
